package org.zoomdev.zoom.dao.adapters;

import org.zoomdev.zoom.dao.struct.ColumnMeta;

import java.lang.reflect.Type;

public abstract class EntityField implements Cloneable {
    protected final String table;
    protected final String column;


    protected final String fieldName;
    protected final ColumnMeta columnMeta;
    protected final StatementAdapter statementAdapter;
    protected final ResultSetAdapter resultSetAdapter;
    protected final Type fieldType;


    public EntityField(ColumnMeta columnMeta,
                       String fieldName,
                       Type fieldType,
                       StatementAdapter statementAdapter,
                       ResultSetAdapter resultSetAdapter) {
        this.column = columnMeta.getName();
        this.table = columnMeta.getTable();
        this.columnMeta = columnMeta;
        this.fieldType = fieldType;
        this.fieldName = fieldName;
        this.statementAdapter = statementAdapter;
        this.resultSetAdapter = resultSetAdapter;
    }

    public String getTable() {
        return table;
    }

    public Type getFieldType() {
        return fieldType;
    }

    public ResultSetAdapter getResultSetAdapter() {
        return resultSetAdapter;
    }

    public ColumnMeta getColumnMeta() {
        return columnMeta;
    }

    public String getFieldName() {
        return fieldName;
    }

    public abstract Object get(Object target);

    public abstract void set(Object target, Object value);

    /**
     * 字段名称（数据库）
     *
     * @return
     */
    public String getColumn() {
        return column;
    }


    /**
     * PrepareStatement 的适配器
     *
     * @return
     */
    public StatementAdapter getStatementAdapter() {
        return statementAdapter;
    }


}
